package com.mz361.common.utils;

import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SendMessageUtil {
    @Autowired
    SmsClient smsClient;

    // 验证身份
    public void sendMsg(String phones, String code, String type) {
        log.info("method【SendVerifyMessage】：phones：{} code：{} type: {}", phones, code, type);
        try {

            SendSmsRequest req = new SendSmsRequest();
            req.setSmsSdkAppId("1400918312");
            req.setSignName("满智北京科技");
            switch (type) {
                case "1"://登录验证码
                    req.setTemplateId("2464642");
                    break;
                case "2"://修改密码验证码
                    req.setTemplateId("2224584");
                    break;
                case "3"://发票申请通知
                    req.setTemplateId("2224580");
                    break;
                default://注册验证码
                    req.setTemplateId("2186858");
                    break;
            }

            String[] templateParamSet = {code};
            req.setTemplateParamSet(templateParamSet);
            String[] phoneNumberSet = {phones};
            req.setPhoneNumberSet(phoneNumberSet);
            SendSmsResponse res = smsClient.SendSms(req);
            System.out.println(SendSmsResponse.toJsonString(res));

        } catch (Exception e) {
            log.info("method【SendVerifyMessage】{}", e.getMessage());
        }
    }

}
